// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.IndexManagement
{
	public sealed partial class SlowlogSettings
	{
		[JsonInclude]
		[JsonPropertyName("level")]
		public string? Level { get; set; }

		[JsonInclude]
		[JsonPropertyName("reformat")]
		public bool? Reformat { get; set; }

		[JsonInclude]
		[JsonPropertyName("source")]
		public int? Source { get; set; }

		[JsonInclude]
		[JsonPropertyName("threshold")]
		public Elastic.Clients.Elasticsearch.IndexManagement.SlowlogTresholds? Threshold { get; set; }
	}

	public sealed partial class SlowlogSettingsDescriptor : SerializableDescriptorBase<SlowlogSettingsDescriptor>
	{
		internal SlowlogSettingsDescriptor(Action<SlowlogSettingsDescriptor> configure) => configure.Invoke(this);
		public SlowlogSettingsDescriptor() : base()
		{
		}

		private string? LevelValue { get; set; }

		private bool? ReformatValue { get; set; }

		private int? SourceValue { get; set; }

		private Elastic.Clients.Elasticsearch.IndexManagement.SlowlogTresholds? ThresholdValue { get; set; }

		private SlowlogTresholdsDescriptor ThresholdDescriptor { get; set; }

		private Action<SlowlogTresholdsDescriptor> ThresholdDescriptorAction { get; set; }

		public SlowlogSettingsDescriptor Level(string? level)
		{
			LevelValue = level;
			return Self;
		}

		public SlowlogSettingsDescriptor Reformat(bool? reformat = true)
		{
			ReformatValue = reformat;
			return Self;
		}

		public SlowlogSettingsDescriptor Source(int? source)
		{
			SourceValue = source;
			return Self;
		}

		public SlowlogSettingsDescriptor Threshold(Elastic.Clients.Elasticsearch.IndexManagement.SlowlogTresholds? threshold)
		{
			ThresholdDescriptor = null;
			ThresholdDescriptorAction = null;
			ThresholdValue = threshold;
			return Self;
		}

		public SlowlogSettingsDescriptor Threshold(SlowlogTresholdsDescriptor descriptor)
		{
			ThresholdValue = null;
			ThresholdDescriptorAction = null;
			ThresholdDescriptor = descriptor;
			return Self;
		}

		public SlowlogSettingsDescriptor Threshold(Action<SlowlogTresholdsDescriptor> configure)
		{
			ThresholdValue = null;
			ThresholdDescriptor = null;
			ThresholdDescriptorAction = configure;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (!string.IsNullOrEmpty(LevelValue))
			{
				writer.WritePropertyName("level");
				writer.WriteStringValue(LevelValue);
			}

			if (ReformatValue.HasValue)
			{
				writer.WritePropertyName("reformat");
				writer.WriteBooleanValue(ReformatValue.Value);
			}

			if (SourceValue.HasValue)
			{
				writer.WritePropertyName("source");
				writer.WriteNumberValue(SourceValue.Value);
			}

			if (ThresholdDescriptor is not null)
			{
				writer.WritePropertyName("threshold");
				JsonSerializer.Serialize(writer, ThresholdDescriptor, options);
			}
			else if (ThresholdDescriptorAction is not null)
			{
				writer.WritePropertyName("threshold");
				JsonSerializer.Serialize(writer, new SlowlogTresholdsDescriptor(ThresholdDescriptorAction), options);
			}
			else if (ThresholdValue is not null)
			{
				writer.WritePropertyName("threshold");
				JsonSerializer.Serialize(writer, ThresholdValue, options);
			}

			writer.WriteEndObject();
		}
	}
}